package com.example.springbootdemo.controller.rest;

import com.alibaba.fastjson.JSONObject;
import com.example.springbootdemo.entity.WecSupplierSpecWithBLOBs;
import com.example.springbootdemo.service.ProductServiceImpl;
import com.example.springbootdemo.setvalue.AuthorSetting;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@Api(value = "TestController", description = "商品信息")
public class TestController {

    @Value("${author.name}")
    private String authorName;
    @Value("${author.iponeNum}")
    private String authorIponeNum;

    @Resource
    private ProductServiceImpl productService;

    @Autowired
    private AuthorSetting authorSetting;

    @GetMapping("/hello")
    @ApiOperation(value = "测试MVC", notes = "测试MVC", produces = "application/json; charset=utf-8")
    public String hello() {
        List<JSONObject> list = new ArrayList<>();
        JSONObject map = new JSONObject();
        map.put("urlName", "百度");
        map.put("likeUrl", "https://www.baidu.com");
        list.add(map);
        map = new JSONObject();

        map.put("urlName", "腾讯");
        map.put("likeUrl", "https://www.qq.com");
        list.add(map);
        map = new JSONObject();

        map.put("urlName", "淘宝");
        map.put("likeUrl", "https://www.taobao.com");
        list.add(map);
        map = new JSONObject();

        map.put("urlName", "头条");
        map.put("likeUrl", "https://www.toutiao.com/");
        list.add(map);
        map = new JSONObject();

        map.put("urlName", "京东");
        map.put("likeUrl", "https://www.jd.com");
        list.add(map);
        return list.toString();
    }

    @GetMapping("/getProductById")
    @ApiOperation(value = "获取商品信息", notes = "获取商品信息", produces = "application/json; charset=utf-8")
    public WecSupplierSpecWithBLOBs getProductById(
            @ApiParam(name = "id", value = "商品id", defaultValue = "", required = true) @RequestParam(required = true) Long id) {
        return productService.getProductById(id);
    }
}
